/** 
* All Rights Reserved , Copyright (C) 2022 , 青岛鼎信通讯股份有限公司
* 
* MpmProjectCustomerDecisionService
* 项目立项-客户决策
* 
* 修改纪录
* 2022-02-15 版本：1.0 houyuhang 创建。
* @version 版本：1.0
* @author 作者：houyuhang
* 创建日期：2022-02-15
*/
package com.topscomm.mpm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.mpm.pojo.MpmProjectBidDateEntity;
import com.topscomm.mpm.pojo.MpmProjectCustomerDecisionEntity;
import com.topscomm.pub.util.StringBufferProxy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.mpm.service.IMpmProjectCustomerDecisionService;
import com.topscomm.mpm.service.impl.auto.MpmProjectCustomerDecisionServiceAuto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service(value = "mpmProjectCustomerDecisionService")
@Scope(value = "singleton")
public class MpmProjectCustomerDecisionService extends MpmProjectCustomerDecisionServiceAuto implements IMpmProjectCustomerDecisionService {
    /**
     * @Title: removeAndAddBidDate
     * @description: 新增或更新挂网开标日期信息记录
     * @param
     * @return
     * @author: houyuhang
     * @date: 2022-01-21
     * @modify:
     */
    public void removeAndAddCustomerDecision(Object object,long id) {
        if(id == 0) {
            return;
        }
        if(object == null) {
            return;
        }
        // 删除原客户决策信息
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle(" {0} = '{1}' ", MpmProjectCustomerDecisionEntity.FieldProjectid, id);
        this.deleteByWhere(sql.toString());
        // 生成客户决策信息
        List<Map<String,Object>> customerDecisionList = (List<Map<String,Object>>) object;
        List<BasicEntity> basicEntities = new ArrayList<>();
        for(Map<String,Object> customerDecision : customerDecisionList) {
            MpmProjectCustomerDecisionEntity mpmProjectCustomerDecisionEntity = new MpmProjectCustomerDecisionEntity();
            mpmProjectCustomerDecisionEntity.convertFromMap(customerDecision);
            mpmProjectCustomerDecisionEntity.setProjectid(id);
            mpmProjectCustomerDecisionEntity.setFinishwritetime(new Date());
            basicEntities.add(mpmProjectCustomerDecisionEntity);
        }
        this.insertBatch(basicEntities);
    }
    /**
     * @Title: beforeInsert
     * @description: 为客户决策增加一条记录时，为填写日期赋值
     * @param
     * @return
     * @author: houyuhang
     * @date: 2022-01-21
     * @modify:
     */
    @Override
    public void beforeInsert(BasicEntity entity) {
        entity.setValue(MpmProjectCustomerDecisionEntity.FieldFinishwritetime,new Date());
    }
}
